﻿using System;
using System.Data;
using System.Configuration;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using RuleCode.Table;
using System.Web.Script.Serialization;
using RuleCode.Common;
using System.Collections.Generic;


public class AjaxFunction
{
    [AjaxPro.AjaxMethod]
    public string Getselarea1(string id)
    {
        区域 q = 区域.Find("区编码 = '" + id + "'");
        string result = string.Empty;
        foreach (DataRow item in q.MyTable.Rows)
        {
            result += "&nbsp;<a href=\"#\"  id=\"a" + item["recid"].ToString() + "\" onclick=\"selarea2('" + 
                item["recid"] + "')\">" + item["区域编码"] + "</a>&nbsp;";
            //result += "&nbsp;<a href=\"javascript:;\" onclick=\"selarea2('" + 
            //    item["recid"] + "')\">" + item["区域编码"] + "</a>&nbsp;";
        }
        return result;
    }
    [AjaxPro.AjaxMethod]
    public string Getarea3id(string area4id)
    {
        区域 a = 区域.Find("recid=" + area4id);

        return a.区编码.ToString();  
    }

    [AjaxPro.AjaxMethod]
    public string Getselarea2(string id)
    {
        区域 q = 区域.Find("recid =  " + id  );
        string result = string.Empty;
        if (AliApi.appUserId == "")
        {
            result += "0";
        }
        else
        {
            result += "1";
        }
        if (q.taobaolong.Value == 0)
        {
            result += "|" + "116.39679908752441";
        }
        else
        {
            result += "|" + q.taobaolong.ToString();
        }
        if (q.taobaolat.Value == 0)
        {
            result += "|" + "39.917043746896674";
        }
        else
        {
            result += "|" + q.taobaolat.ToString();
        }
        result += "|" + q.区域编码.ToString();
        return result;
    }

    [AjaxPro.AjaxMethod]
    public bool setShopCol(int i,string domid,string htmlstring,string htmlin)
    {
        //cbshop s = cbshop.findorcreate( AliApi.appUserId );
        
        cbshoppage s = cbshoppage.Find(" cbshoppageid = '"
            + cbshop.transhoppageid(i.ToString())
            + "' and cbuserid = '" + AliApi.appUserId + "'");
        cbuser u = cbuser.u();
        htmlstring = htmlstring.Replace("id=" + u.cbuserid.ToString() , "replace=zyj");
        htmlin = htmlin.Replace("id=" + u.cbuserid.ToString() , "replace=zyj");
        if (domid == "dom0")
        {
            s.cbcodea0.Value = htmlstring;
            s.cbcodeb0.Value = htmlin;
        }
        if (domid == "dom1")
        {
            s.cbcodea1.Value = htmlstring;
            s.cbcodeb1.Value = htmlin;
        }
        if (domid == "dom2")
        {
            s.cbcodea2.Value = htmlstring;
            s.cbcodeb2.Value = htmlin;
        }
        if (domid == "dom3")
        {
            s.cbcodea3.Value = htmlstring;
            s.cbcodeb3.Value = htmlin;
        }
        if (domid == "dom4")
        {
            s.cbcodea4.Value = htmlstring;
            s.cbcodeb4.Value = htmlin;
        }
        if (domid == "dom5")
        {
            s.cbcodea5.Value = htmlstring;
            s.cbcodeb5.Value = htmlin;
        }

        s.Modify();
        return true;
    }

    [AjaxPro.AjaxMethod]
    public bool setwzfl(string html)
    {
        cbshoppageelement spe = cbshoppageelement.findorcreatesystem(AliApi.appUserId,
                "网站导航栏");
        spe.cb7.Value = html;
        spe.Modify();
        return true;
    }
    [AjaxPro.AjaxMethod]
    public string getwzfl(string uid)
    {
        cbuser u;
        if (uid == null)
        {
            u = cbuser.Find(" cbuserid='" + AliApi.appUserId+"'");
        }
        else
        {
            u = cbuser.Find("recid=" + uid); ;
        }
        
        cbshoppageelement spe = cbshoppageelement.findorcreatesystem(u.cbuserid.ToString(),
                "网站导航栏");
        return spe.cb7.ToString() ;
    }


    [AjaxPro.AjaxMethod]
    public string getShopCol1(int cblanmuing, string domid)
    {
        //cbshop s = cbshop.findorcreate(AliApi.appUserId);
        cbuser u = cbuser.Find(" cbuserid = '" + AliApi.appUserId + "'");
        string cblanmu = cblanmuing.ToString();
        cbshoppage s = cbshoppage.Find(" cbshoppageid = '"
            + cbshop.transhoppageid(cblanmu)
            + "' and cbuserid = '" + AliApi.appUserId + "'");
        if (domid == "dom0")
        {
            return s.cbcodea0.ToString().Replace("replace=zyj", "id=" + u.RECID.ToString());
        }
        if (domid == "dom1")
        {
            return s.cbcodea1.ToString().Replace("replace=zyj", "id=" + u.RECID.ToString());
        }
        if (domid == "dom2")
        {
            return s.cbcodea2.ToString().Replace("replace=zyj", "id=" + u.RECID.ToString());
        }
        if (domid == "dom3")
        {
            return s.cbcodea3.ToString().Replace("replace=zyj", "id=" + u.RECID.ToString());
        }
        if (domid == "dom4")
        {
            return s.cbcodea4.ToString().Replace("replace=zyj", "id=" + u.RECID.ToString());
        }
        if (domid == "dom5")
        {
            return s.cbcodea5.ToString().Replace("replace=zyj", "id=" + u.RECID.ToString());
        }
        return "";
    }

    #region add by dingyuliang
    #region 交易相关

    /// <summary>
    /// 修改交易订单的价格
    /// </summary>
    /// <param name="tradeRecid"></param>
    /// <returns></returns>
    [AjaxPro.AjaxMethod ]
    public string ModifyTradePrice(string tradeRecid,float  newPrice)
    {
        string result = string.Empty;
        taobaotrade trade = taobaotrade.Find("recid="+tradeRecid );
        if (trade.Count > 0)
        {
            trade.taobaopayment.Value = newPrice.ToString ();
            trade.Modify(); 
        }
        else
        {
            result = "对不起，没有找到您的订单";
        }
        return result;
    }
    #endregion


    #region 宝贝分类相关
    /// <summary>
    /// 根据 父目录属性 获取所有的子目录 json格式返回
    /// </summary>
    /// <param name="parentCate">父目录</param>
    /// <returns></returns>
    [AjaxPro.AjaxMethod]
    public string GetItemCate(string parentCate)
    {
        if (parentCate == "")
            parentCate = "1"; //顶级目录分类

        string result = string.Empty;
        string filter = "taobaoparentsyscatid='" + parentCate + "'";
        taobaosyscat syscat = taobaosyscat.Find(filter);
        if (syscat.Count > 0)
        {
            int index = 0;
            result = "{[";
            do
            {
                if (index++ > 0)
                {
                    result += ",";
                }
                result += "{id:'" + syscat.taobaosyscatid.Value + "',name:'" + syscat.taobaoname.Value + "'}";
            } while (syscat.Next());
            result += "]}";
        }
        return result;
    }

    /// <summary>
    /// 根据 目录关键字搜索 所有包含关键字的目录 json 格式返回
    /// </summary>
    /// <param name="cateKey">目录关键字</param>
    /// <returns></returns>
    [AjaxPro .AjaxMethod ]
    public string SearchItemCate(string cateKey)
    {
        string result = string.Empty;
        if (cateKey.Trim() == "")
            return result;

        string filter = "taobaoname like '%"+cateKey +"%'";
        taobaosyscat syscat = taobaosyscat.Find(filter );
        if (syscat.Count > 0)
        {
            int index = 0;
            result = "{[";
            do
            {             
                string ids = string.Empty;
                string names = string.Empty;
                if (index++ > 0)
                {
                    result += ",";
                }
                int count = 0;
                if (ValidateSysCateId( syscat.p3.Value))
                {
                    if (count++ > 0)
                    {
                        ids += ",";
                        names += ",";
                    }
                    ids +="'"+ syscat.p3.Value+"'";
                    names += "'" + GetSysCateName(syscat.p3.Value) + "'";
                }
                if (ValidateSysCateId(syscat.p2.Value))
                {
                    if (count++ > 0)
                    {
                        ids += ",";
                        names += ",";
                    }
                    ids += "'" + syscat.p2.Value + "'";
                    names += "'" + GetSysCateName(syscat.p2.Value) + "'";
                }
                if (ValidateSysCateId(syscat.taobaoparentsyscatid.Value))
                {
                    if (count++ > 0)
                    {
                        ids += ",";
                        names += ",";
                    }
                    ids += "'" + syscat.taobaoparentsyscatid.Value + "'";
                    names += "'" + GetSysCateName(syscat.taobaoparentsyscatid.Value) + "'";
                }
                if (ValidateSysCateId(syscat.taobaosyscatid.Value))
                {
                    if (count++ > 0)
                    {
                        ids += ",";
                        names += ",";
                    }
                    ids += "'" + syscat.taobaosyscatid.Value + "'";
                    names += "'" + syscat.taobaoname.Value + "'";
                }
                result += "{ids:[" + ids +"],names:["+names+  "]}";
            } while (syscat.Next());
            result += "]}";
        }
        return result;
    }

    /// <summary>
    /// 根据 类目Id值获取类目名称列表
    /// </summary>
    /// <param name="cateIds">格式 id1_id2_id3</param>
    /// <returns></returns>
    [AjaxPro .AjaxMethod ]
    public string GetCateNameListFromIds(string cateIds)
    {
        string cateNames = string.Empty;
        if (cateIds.Trim () != string.Empty )
        {
            string[] cateIdArgs = cateIds.Split("_".ToCharArray ());
            if (cateIdArgs != null && cateIdArgs.Length > 0)
            {
                cateNames = "{[";
                int count = 0;
                for (int i = 0; i < cateIdArgs.Length; i++)
                {
                    taobaosyscat syscate = taobaosyscat.Find("taobaosyscatid='"+cateIdArgs [i]+"'");
                    if (syscate.Count > 0)
                    {
                        if (count++ > 0)
                            cateNames += ",";
                        cateNames += "{Name:'"+syscate.taobaoname.Value + "'}";
                    }
                }
                cateNames += "]}";
            }
        }
        return cateNames;
    }


    /// <summary>
    /// 根据 最终的 类目id获取该类目的所有的父级id列表,json数组格式
    /// </summary>
    /// <param name="lastCateId"></param>
    /// <returns></returns>
    [AjaxPro.AjaxMethod ]
    public string GetCateIdNames(string lastCateId)
    {
        string cateIds = string.Empty;
        if (lastCateId.Trim () != "")
        {
            taobaosyscat syscat = taobaosyscat.Find("taobaosyscatid='"+lastCateId +"'");
            if (syscat.Count > 0)
            {
                string ids = string.Empty;
                string names = string.Empty;
                int count = 0;
                if (ValidateSysCateId(syscat.p3.Value))
                {
                    if (count++ > 0)
                    {
                        ids += ",";
                        names += ",";
                    }
                    ids += "'" + syscat.p3.Value + "'";
                    names += "'" + GetSysCateName(syscat.p3.Value) + "'";
                }
                if (ValidateSysCateId(syscat.p2.Value))
                {
                    if (count++ > 0)
                    {
                        ids += ",";
                        names += ",";
                    }
                    ids += "'" + syscat.p2.Value + "'";
                    names += "'" + GetSysCateName(syscat.p2.Value) + "'";
                }
                if (ValidateSysCateId(syscat.taobaoparentsyscatid.Value))
                {
                    if (count++ > 0)
                    {
                        ids += ",";
                        names += ",";
                    }
                    ids += "'" + syscat.taobaoparentsyscatid.Value + "'";
                    names += "'" + GetSysCateName(syscat.taobaoparentsyscatid.Value) + "'";
                }
                if (ValidateSysCateId(syscat.taobaosyscatid.Value))
                {
                    if (count++ > 0)
                    {
                        ids += ",";
                        names += ",";
                    }
                    ids += "'" + syscat.taobaosyscatid.Value + "'";
                    names += "'" + syscat.taobaoname.Value + "'";
                }
                cateIds = "{ids:[" + ids + "],names:[" + names + "]}";
            }
        }
        return cateIds;
    }
    #endregion

    #region 宝贝信息相关
    /// <summary>
    /// 获取所有的省份 （包括国外）
    /// </summary>
    /// <returns></returns>
    [AjaxPro.AjaxMethod ]
    public string GetAllStates()
    {
        string allStates = string.Empty;
        taobaostate state = new taobaostate();
        state.EnablePage = false;
        state.Init(-1);
        if (state.Count > 0)
        {
            allStates = "{[";
            int count = 0;
            do
            {
                if (state.taobaostateid.Value != "海外")
                {
                    if (count++ > 0)
                        allStates += ",";
                    allStates += "{state:'" + state.taobaostateid.Value + "'}";
                }
            } while (state.Next());
            allStates += "]}";
        }
        return allStates;
    }

    /// <summary>
    /// 根据某一个省份获取该省份的所有的城市
    /// </summary>
    /// <param name="stateId">省份</param>
    /// <returns></returns>
    [AjaxPro.AjaxMethod ]
    public string GetAllCitys(string stateId)
    {
        string allCitys = string.Empty;
        string filter = "taobaostateid='"+stateId +"'";
        taobaocity city = taobaocity.Find(filter);
        if (city.Count > 0)
        {
            allCitys = "{[";
            int count = 0; 
            do{
                if (count++ > 0)
                    allCitys += ",";
                allCitys += "{city:'"+city .taobaocityid .Value +"'}";
            }while(city .Next());
            allCitys += "]}";
        }
        return allCitys;
    }

    /// <summary>
    /// 新建或者修改宝贝信息
    /// </summary>
    /// <param name="isnew">确定是新建还是修改宝贝信息</param>
    /// <param name="itemid"></param>
    /// <param name="itemcid"></param>
    /// <param name="type"></param>
    /// <param name="title"></param>
    /// <param name="price"></param>
    /// <param name="count"></param>
    /// <param name="imgPath"></param>
    /// <param name="desc"></param>
    /// <param name="state"></param>
    /// <param name="city"></param>
    /// <param name="feePayer"></param>
    /// <param name="postfee"></param>
    /// <param name="expressfee"></param>
    /// <param name="emsfee"></param>
    /// <param name="hasdiscount"></param>
    /// <param name="validthu"></param>
    /// <param name="hasinvoice"></param>
    /// <param name="haswarranty"></param>
    /// <param name="autoRepost"></param>
    /// <param name="showcase"></param>
    /// <returns>返回更新成功与否</returns>
    [AjaxPro .AjaxMethod ]
    public bool UpdateItem(bool isnew,string itemid,string itemcid,string type,string title,float  price,int count,
        string imgPath,string desc,string state,string city,string feePayer,float postfee,float expressfee,
        float emsfee, string hasdiscount, int validthu, string hasinvoice, string haswarranty, string autoRepost,
        string showcase,string seller_cids)
    {
        try
        {
            if (AliApi.appUserId != "")
            {
                taobaouseritems useritems;
                if (isnew == true)
                {
                    useritems = taobaouseritems.Find("1=2");
                    useritems.New();
                    useritems.taobaoiid.Value = GetGuidId();          
                }
                else
                {
                    useritems = taobaouseritems.Find("taobaoiid='" + itemid + "' and  taobaouserid='" + AliApi.appUserId + "'");
                    if (useritems.Count <= 0)
                        return false ;
                }
                useritems.taobaoUserId.Value = AliApi.appUserId;
                useritems.taobaoNickName.Value = AliApi.appNickName;
                useritems.taobaocid.Value = itemcid;
                useritems.taobaotitle.Value = title;
                useritems.taobaoitemtype.Value = "fixed";
                useritems.taobaostuff_status.Value = type;
                useritems.taobaoprice.Value = price.ToString();
                useritems.taobaonum.Value = count;
                useritems.taobaopic_path.Value = imgPath;
                useritems.taobaodesc.Value = desc;
                useritems.taobaostate.Value = state;
                useritems.taobaocity.Value = city;
                useritems.taobaofreight_payer.Value = feePayer;
                useritems.taobaopost_fee.Value = postfee.ToString();
                useritems.taobaoexpress_fee.Value = expressfee.ToString();
                useritems.taobaoems_fee.Value = emsfee.ToString();
                useritems.taobaohas_discount.Value = hasdiscount.ToString();
                useritems.taobaohas_invoice.Value = hasinvoice.ToString();
                useritems.taobaohas_showcase.Value = showcase.ToString();
                useritems.taobaohas_warranty.Value = haswarranty.ToString();
                useritems.taobaoauto_repost.Value = autoRepost.ToString();
                useritems.taobaovalid_thru.Value = validthu.ToString();

                useritems.taobaoseller_cids.Value = seller_cids;
                useritems.taobaolist_time.Value = DateTime.Now.ToString();
                if (isnew == true)
                    useritems.Insert();
                else
                    useritems.Modify();

            }
        }
        catch 
        {
             return  false;
        }
        return true;
    }

    /// <summary>
    /// 根据 宝贝的id获取 宝贝的具体信息
    /// </summary>
    /// <param name="itemiid"></param>
    /// <returns></returns>
    [AjaxPro .AjaxMethod ]
    public string GetItemInfo(string itemiid)
    {
        string itemInfo = string.Empty;
        if (itemiid.Trim() != string.Empty)
        {
            string filter = "taobaoiid = '"+itemiid +"'";
            taobaouseritems useritems = taobaouseritems.Find(filter );
            if (useritems.Count > 0)
            {
                itemInfo = "{";
                itemInfo += "itemid:'"+useritems.taobaoiid.ToString()+"'";
                itemInfo += ",itemcid:'" + useritems.taobaocid .ToString() + "'";
                itemInfo += ",type:'" + useritems.taobaostuff_status .ToString() + "'";
                itemInfo += ",title:'" + useritems.taobaotitle.ToString() + "'";
                itemInfo += ",price:'" + useritems.taobaoprice.ToString() + "'";
                itemInfo += ",count:'" + useritems.taobaonum.ToString() + "'";
                itemInfo += ",imgPath:'" + useritems.taobaopic_path .ToString() + "'";
                itemInfo += ",desc:'" + useritems.taobaodesc.ToString() + "'";
                itemInfo += ",state:'" + useritems.taobaostate .ToString() + "'";
                itemInfo += ",city:'" + useritems.taobaocity .ToString() + "'";
                itemInfo += ",feePayer:'" + useritems.taobaofreight_payer .ToString() + "'";
                itemInfo += ",postfee:'" + useritems.taobaopost_fee .ToString() + "'";
                itemInfo += ",expressfee:'" + useritems.taobaoexpress_fee .ToString() + "'";
                itemInfo += ",emsfee:'" + useritems.taobaoems_fee.ToString() + "'";
                itemInfo += ",hasdiscount:'" + useritems.taobaohas_discount .ToString() + "'";
                itemInfo += ",validthu:'" + useritems.taobaovalid_thru .ToString() + "'";          
                itemInfo += ",hasinvoice:'" + useritems.taobaohas_invoice .ToString() + "'";
                itemInfo += ",haswarranty:'" + useritems.taobaohas_warranty .ToString() + "'";
                itemInfo += ",seller_cids:'" + useritems.taobaoseller_cids.Value + "'";
                itemInfo += ",autoRepost:" + ((useritems.taobaoauto_repost .ToString()=="true")?"true":"false") + "";
                itemInfo += ",showcase:" + ((useritems.taobaohas_showcase.ToString() == "true") ? "true" : "false") + "";

                string cIdNames = GetCateIdNames(useritems.taobaocid.Value);
                itemInfo += ",cIdNames:"+(cIdNames==""?"{}":cIdNames) ;

                itemInfo += "}";
            }
        }
        return itemInfo;
    }
    #endregion

    #region 辅助方法
    /// <summary>
    /// 获取GUID，动态分配宝贝的id等需要唯一确认的信息
    /// </summary>
    /// <returns></returns>
    [AjaxPro.AjaxMethod]
    public string GetGuidId()
    {
        return Guid.NewGuid().ToString("N");
    }

    private bool ValidateSysCateId(string syscateId)
    {
        return syscateId != null && syscateId.Trim() != string.Empty && syscateId.Trim() != "0" && syscateId.Trim() != "1";
    }
    private string GetSysCateName(string syscateId)
    {
        string resultName = string.Empty;
        string filter = "taobaosyscatid='"+syscateId +"'";
        taobaosyscat syscat = taobaosyscat.Find(filter);
        if (syscat.Count > 0)
            resultName = syscat.taobaoname.Value;
        return resultName;
    }
    #endregion

    #region pfriends 页面方法
    /// <summary>
    /// 获取 个人的大学，高中，初中，上班单位
    /// </summary>
    /// <returns></returns>
    [AjaxPro.AjaxMethod ]
    public string GetPersonalRelationInfo(string userid)
    {
        userid = (userid == "") ? AliApi.appUserId : userid;
        string result = string.Empty;
        if (userid != string.Empty)
        {
            string filter = "cbuserid='" + userid + "'";
            cbuser user = cbuser.Find(filter );
            if (user.Count > 0)
            {
                result = "{[";
                result += "{Type:'1',Name:'"+user.JuniorSchoolName .Value +"',Year:"+user.JuniorSchoolGraduateYear.ToString ()+"}";
                result += ",{Type:'2',Name:'" + user.SeniorSchoolName.Value + "',Year:" + user.SeniorSchoolGraduateYear.ToString() + "}";
                result += ",{Type:'3',Name:'" + user.ColleageName.Value + "',Year:" + user.ColleageGraduateYear.ToString() + "}";
                result += ",{Type:'4',Name:'"+user.LastEmployeeName .Value +"',Year:0}";
                result += "]}";
            }
        }
        return result;
    }

    /// <summary>
    /// 搜索符合要求的可能的好友
    /// </summary>
    /// <returns></returns>
    [AjaxPro .AjaxMethod ]
    public string SearchFriendsByPersonalInfo(string type,string nameref,int yearref,int count)
    {
        string filter =string.Empty ;
        string result = string.Empty;
        switch (type)
        {
            case "0":                                 //可以是 姓名，工作单位，或者学校
                {
                    filter = " cbname like '%" + nameref + "%' " + " or LastEmployeeName like '%" + nameref + "%' "
                        + " or SeniorSchoolName like '%" + nameref + "%' " + " or JuniorSchoolName like '%" + nameref + "%' "
                        + " or ColleageName like '%" + nameref + "%' ";
                    break;
                }
            case "1":                                 //初中
                {
                    filter = "JuniorSchoolName like '%" + nameref + "%' and JuniorSchoolGraduateYear=" + yearref;
                    break;
                }
            case "2":                                 //高中
                {
                    filter = "SeniorSchoolName like '%" + nameref + "%' and SeniorSchoolGraduateYear=" + yearref;
                    break;
                }
            case "3":                                 //大学
                {
                    filter = "ColleageName like '%" + nameref + "%' and ColleageGraduateYear="+yearref ;
                    break;
                }
            case "4":                                 //单位
                {
                    filter = " LastEmployeeName like '%"+nameref +"%'";
                    break;
                }
            default: 
                {
                    break;
                }
        }
        if (filter != string.Empty &&　AliApi.appUserId !="")
        {
            filter += " and cbuserid!='" +AliApi.appUserId + "'";
            cbuser user = cbuser.Find(filter );
            if (user.Count > 0)
            {
                if (count <= 0)
                    count = user.Count;
                count = Math.Min (count, user.Count);
                result = "{[";
                for (int i = 0; i < count; i++)
                {
                    if (i > 0)
                        result += ",";
                    result += "{";
                    result += "RECID:'" + user.RECID.ToString() + "'";
                    result += ",cbuserid:'" + user.cbuserid.ToString() + "'";
                    result += ",cbname:'" + user.cbname.ToString() + "'";
                    result += ",sSchoolName:'" + user.SeniorSchoolName.ToString() + "'";
                    result += ",sSchoolYear:" + user.SeniorSchoolGraduateYear.ToString();
                    result += ",jSchoolName:'" + user.JuniorSchoolName .ToString() + "'";
                    result += ",jSchoolYear:" + user.JuniorSchoolGraduateYear .ToString() ;
                    result += ",collageName:'" + user.ColleageName .ToString() + "'";
                    result += ",collageYear:" + user.ColleageGraduateYear .ToString() ;
                    result += ",LastEmployeeName:'" + user.LastEmployeeName.ToString() + "'";
                    result += ",ImgPath:'" + ((user.cbimgpath.Value == "") ? "../img/userdefaultimg.gif" : user.cbimgpath.Value) + "'";
                    result +="}";
                    user.Next();
                }
                result += "]}";
            }
        }
        return result;
    }

    [AjaxPro.AjaxMethod ]
    public string SearchPosibleFriends(string type, string nameref, int yearref, int count)
    {                    
        string filter = string.Empty;
        string result = string.Empty;
        if (AliApi.appUserId != string.Empty)
        {
            switch (type)
            {
                case "0":                                 //可以是 姓名，工作单位，或者学校
                    {
                        filter = "@userid='" + AliApi.appUserId + "'" + ",@searchKeys='" + nameref + "'";
                        break;
                    }
                case "1":                                 //初中
                    {
                        filter = "@userid='" + AliApi.appUserId + "'" + ",@jSchoolName = '" + nameref + "' , @jSchoolYear=" + yearref;
                        break;
                    }
                case "2":                                 //高中
                    {
                        filter = "@userid='" + AliApi.appUserId + "'" + ",@sSchoolName like '" + nameref + "' , @sSchoolYear=" + yearref;
                        break;
                    }
                case "3":                                 //大学
                    {
                        filter = "@userid='" + AliApi.appUserId + "'" + ",@collageName like '" + nameref + "' , @collageYear=" + yearref;
                        break;
                    }
                case "4":                                 //单位
                    {
                        filter = "@userid='"+AliApi.appUserId +"'" + ", @lastEmployeeName like '%" + nameref + "%'";
                        break;
                    }
                default:
                    {
                        break;
                    }
            }
        }

        if (filter != string.Empty )
        {
            string SqlText = " exec [SearchRelationFriends] " + filter;
            DataSet dSet = SqlHelper.Instance.ExecuteQuery(SqlText);
            if (dSet.Tables.Count > 0 && dSet.Tables[0].Rows.Count > 0)
            {
                if (count <= 0)
                    count = dSet.Tables[0].Rows.Count;
                count = Math.Min(count, dSet.Tables[0].Rows.Count);
                result = "{[";
                for (int i = 0; i < count; i++)
                {
                    if (i > 0)
                        result += ",";
                    result += "{";
                    result += "RECID:'" + dSet.Tables[0].Rows[i]["RECID"].ToString() + "'";
                    result += ",cbuserid:'" + dSet.Tables[0].Rows[i]["cbuserid"].ToString() + "'";
                    result += ",cbname:'" + dSet.Tables[0].Rows[i]["cbname"].ToString() + "'";
                    result += ",sSchoolName:'" + dSet.Tables[0].Rows[i]["SeniorSchoolName"].ToString() + "'";
                    result += ",sSchoolYear:" + dSet.Tables[0].Rows[i]["SeniorSchoolGraduateYear"].ToString();
                    result += ",jSchoolName:'" + dSet.Tables[0].Rows[i]["JuniorSchoolName"].ToString() + "'";
                    result += ",jSchoolYear:" + dSet.Tables[0].Rows[i]["JuniorSchoolGraduateYear"].ToString();
                    result += ",collageName:'" + dSet.Tables[0].Rows[i]["ColleageName"].ToString() + "'";
                    result += ",collageYear:" + dSet.Tables[0].Rows[i]["ColleageGraduateYear"].ToString();
                    result += ",LastEmployeeName:'" + dSet.Tables[0].Rows[i]["LastEmployeeName"].ToString() + "'";
                    result += ",ImgPath:'" + ((dSet.Tables[0].Rows[i]["cbimgpath"].ToString() == "") ? "../img/userdefaultimg.gif" : dSet.Tables[0].Rows[i]["cbimgpath"].ToString()) + "'";
                    result += "}";
                }
                result += "]}";
            }
        }
        return result;
    }
    #endregion

    #region 好友以及好友分组相关

    [AjaxPro.AjaxMethod]
    public string GetCurrentGroupList()
    {
        string result = string.Empty;
        if (AliApi.appUserId != string.Empty)
        {
            cbusergroup usergroup = cbusergroup.Find("cbuserid='" + AliApi.appUserId + "'");
            if (usergroup.Count > 0)
            {
                result = "{[";
                for (int i = 0; i < usergroup.Count; i++)
                {
                    if (i > 0)
                        result += ",";
                    result += "{id:'" + usergroup.cbusergroupid.Value + "',name:'" + usergroup.cbname.Value + "'}";
                    usergroup.Next();
                }
                result += "]}";
            }
        }
        return result;
    }

    [AjaxPro.AjaxMethod ]
    public string  AddNewFriend(string usergroupid, string userid, string usernick)
    {
        try
        {
            string sql = "select * from cbusergrouplist where cbuserid='" + userid + "' and cbusergroupid in (select cbusergroupid from cbusergroup where cbuserid='" + AliApi.appUserId  + "')";
            DataSet dSet = SqlHelper.Instance.ExecuteQuery(sql);
            if (dSet.Tables.Count > 0 && dSet.Tables[0].Rows.Count > 0)
            {
                //MessageBox.Show(this.Page, "该用户已经是好友，不能添加！");
                return "该用户已经是好友，不能添加！";
            }
            cbusergrouplist grouplist = new cbusergrouplist();
            grouplist.Init(0);
            grouplist.New();
            grouplist.cbname.Value = usernick ;
            grouplist.cbusergroupid.Value = usergroupid;
            grouplist.cbuserid.Value = userid;
            grouplist.Insert();
        }
        catch (Exception ep)
        {
            return ep.Message;
        }
        return "";
    }

    [AjaxPro.AjaxMethod ]
    public string AddNewGroup(string newGroupName)
    {
        string result = string.Empty;
        if (AliApi.appUserId != string.Empty)
        {
            cbusergroup usergroup = cbusergroup.Find("cbuserid='"+AliApi .appUserId +"' and cbname='"+newGroupName +"'");
            if (usergroup.Count > 0)
            {
                result = "对不起，您输入的分组名称已经存在，请重新输入！";
            }
            else
            {
                usergroup.New();
                usergroup.cbusergroupid.Value = usergroup.GetRecID().ToString() ;
                usergroup.cbname.Value = newGroupName;
                usergroup.cbuserid.Value = AliApi.appUserId;
                usergroup.Insert();
            }
        }
        else
        {
            result = "您还未登录！";
        }
        return result;
    }

    [AjaxPro .AjaxMethod ]
    public string getUserFriendGroupList(string userid)
    {
        string result = string.Empty;
        if (userid != string.Empty)
        {
            cbusergroup usergroup = cbusergroup.Find("cbuserid='"+userid +"'");
            if (usergroup.Count > 0)
            {
                result = "{[";
                for (int i = 0; i < usergroup.Count; i++)
                {
                    if (i > 0)
                        result += ",";
                    result += "{groupid:'" + usergroup.cbusergroupid.Value + "',groupname:'" + usergroup.cbname.Value + "'}";
                    usergroup.Next();
                }
                result += "]}";
            }
        }
        return result;
    }

    [AjaxPro.AjaxMethod ]
    public string GetGroupFriend(string grouplistRecid)
    {
        string result = string.Empty;
        cbusergrouplist grouplist = cbusergrouplist.Find("RECID=" + grouplistRecid);
        if (grouplist.Count > 0)
        {
            result = "{";
            result += "groupid:'"+grouplist .cbusergroupid .Value +"'";
            result += ",username:'"+grouplist .cbname .Value +"'";
            result += ",userid:'" + grouplist.cbuserid.Value + "'";
            result += "}";
        }
        return result;
    }

    [AjaxPro.AjaxMethod ]
    public string GetFriendsInGroup(string groupId)
    {
        string result = string.Empty;
        string SqlText = "exec [GetFriends] @userid='"+AliApi .appUserId +"' , @usergroupid='"+groupId +"'";
        DataSet dSet = SqlHelper.Instance.ExecuteQuery(SqlText );
        if (dSet.Tables.Count > 0 && dSet.Tables[0].Rows.Count > 0)
        {
            result = "{[";
            for (int i = 0; i < dSet.Tables[0].Rows.Count; i++)
            {
                if (i > 0)
                    result += ",";
                result += "userid:'" + dSet.Tables[0].Rows[i]["f_cbuserid"].ToString()
                        + "',username:'" + dSet.Tables[0].Rows[i]["my_f_cbname"].ToString() + "'";
            }
            result += "]}";
        }
        return result;
    }

    [AjaxPro .AjaxMethod ]
    public string EditFriendInfo(string groupListRECID, string newName, string newGroupId)
    {
        string result = string.Empty;
        try
        {
            cbusergrouplist grouplist = cbusergrouplist.Find("RECID=" + groupListRECID);
            if (grouplist.Count > 0)
            {
                grouplist.cbusergroupid.Value = newGroupId;
                grouplist.cbname.Value = newName;
                grouplist.Modify();
            }
        }
        catch (Exception e)
        {
            result = e.Message;
        }
        return result;
    }

    [AjaxPro.AjaxMethod ]
    public bool ChangeFriendGroup(string groupList_Recid, string oldGroupId, string newGroupId)
    {
        bool result = false ; 
        if (AliApi.appUserId != string.Empty && newGroupId !=string.Empty )
        {
            string filter = "recid=" + groupList_Recid + " and cbusergroupid='"+oldGroupId  + "' and cbusergroupid in (select cbusergroupid from cbusergroup where cbuserid='"+AliApi .appUserId +"')";
            cbusergrouplist grouplist = cbusergrouplist.Find(filter );
            if (grouplist.Count > 0)
            {
                grouplist.cbusergroupid.Value = newGroupId;
                grouplist.Modify();
                result = true;
            }
        }                                                                    
        return result;
    }

    /// <summary>
    /// 更改好友分组名称
    /// </summary>
    /// <param name="groupid"></param>
    /// <param name="oldName"></param>
    /// <param name="newName"></param>
    /// <returns></returns>
    [AjaxPro.AjaxMethod ]
    public string ChangeGroupName(string groupid, string oldName, string newName)
    {
        string result = string.Empty ;
        if (AliApi.appUserId != string.Empty)
        {
            cbusergroup usergroup = cbusergroup.Find("cbuserid='" + AliApi.appUserId + "' and cbname ='" + oldName + "' and cbusergroupid='" + groupid + "'");
            if (usergroup.Count > 0)
            {
                usergroup.cbname.Value = newName;
                usergroup.Modify();
            }
        }
        else
            result = "您尚未登录，请先登录";
        return result;
    }

    /// <summary>
    /// 删除好友
    /// </summary>
    /// <param name="groupList_Recid"></param>
    /// <returns></returns>
    [AjaxPro .AjaxMethod ]
    public bool deleteFriendInGroup(string groupList_Recid)
    {
        bool result = false;
        if (AliApi.appUserId != string.Empty)
        {
            cbusergrouplist groupList = cbusergrouplist.Find(" recid = "+groupList_Recid+" and cbusergroupid in (select cbusergroupid from cbusergroup where cbuserid='"+AliApi .appUserId +"')");
            if (groupList.Count > 0)
            {
                groupList.Delete();
                result = true;
            }
        }
        return result;
    }

    [AjaxPro.AjaxMethod ]
    public bool deleteUserGroup(string groupid)
    {
        if (AliApi.appUserId != null)
        {
            cbusergroup usergroup = cbusergroup.Find("cbuserid='"+AliApi .appUserId +"' and cbusergroupid='"+groupid +"'");
            if (usergroup.Count > 0)
            {
                usergroup.Delete();
                return true;
            }
        }
        return false;
    }
    #endregion

    #region 自定义分类
    
    /// <summary>
    /// 修改自定义分类的名称
    /// </summary>
    /// <param name="itemcateid"></param>
    /// <param name="oldname"></param>
    /// <param name="newname"></param>
    /// <returns>修改成功返回空，否则返回错误信息</returns>
    [AjaxPro.AjaxMethod ]
    public string renameCateName(string itemcateid, string oldname, string newname)
    {
        string result = string.Empty;
        if (AliApi.appUserId != string.Empty)
        {
            taobaoItemCat taobaoitemcate = taobaoItemCat.Find("taobaouserid='"+AliApi.appUserId +"' and taobaocid='"+itemcateid +"' and taobaoname='"+oldname +"'");
            if (taobaoitemcate.Count > 0)
            {
                taobaoitemcate.taobaoname.Value = newname;
                taobaoitemcate.Modify();
            }
            else
                result = "未找到您查找的自定义分类！";
        }
        else
            result = "您未登录!";
        return result;
    }

    [AjaxPro.AjaxMethod]
    public bool removeItemSellerCate(string itemRecid, string itemcateId)
    {
        bool result = false;
        string filter = " recid=" + itemRecid + " and taobaoseller_cids like '%" + itemcateId + "%'";
        taobaouseritems useritems = taobaouseritems.Find(filter);
        if (useritems.Count > 0)
        {
            string oldSellerCids = useritems.taobaoseller_cids.Value;
            string[] cids = oldSellerCids.Trim().Split(",".ToCharArray());
            string newSellerCids = ",";
            foreach (string cid in cids)
            {
                if (cid.Trim() != string.Empty && cid.Trim() != itemcateId)
                    newSellerCids += cid + ",";
            }
            useritems.taobaoseller_cids.Value = newSellerCids;
            useritems.Modify();
            return true;

        }
        return result;
    }

    /// <summary>
    /// 获取当前用户的叶
    /// </summary>
    /// <returns></returns>
    [AjaxPro.AjaxMethod]
    public string getAllLeaveCate()
    {
        string result = string.Empty;
        if (AliApi.appUserId != string.Empty)
        {

            //result = "{[";
            //for (int i = 0; i < dRowList.Count ; i++)
            //{
            //    if (i > 0)
            //        result += ",";
            //    result += "{";
            //    result += "cid:'" + dRowList[i]["taobaocid"].ToString() + "'";
            //    result += ",name:'" + dRowList[i]["taobaoname"].ToString() + "'";
            //    result += ",pcid:'" + dRowList[i]["ptaobaocid"].ToString() + "'";
            //    result += ",pname:'" + dRowList[i]["ptaobaoname"].ToString() + "'";
            //    result += "}";
            //}
            //result += "]}";
            int index = 0;
            taobaoItemCat taobaoitemcate = taobaoItemCat.Find("taobaouserid='" + AliApi.appUserId + "'");
            DataRow[] firstLevelRows = taobaoitemcate.Select("taobaoparentcid='0'", "taobaosort_order asc");
            foreach (DataRow dRow in firstLevelRows)
            {
                DataRow[] secondLevelRows = taobaoitemcate.Select("taobaoparentcid='" + dRow["taobaocid"].ToString() + "'", "taobaosort_order asc");
                if (secondLevelRows.Length > 0)
                {
                    foreach (DataRow secondRow in secondLevelRows)
                    {
                        if (index++ == 0)
                            result = "{[";
                        else
                            result += ",";
                        result += "{";
                        result += "cid:'" + secondRow["taobaocid"].ToString() + "'";
                        result += ",name:'" + secondRow["taobaoname"].ToString() + "'";
                        result += ",pcid:'" + dRow["taobaocid"].ToString() + "'";
                        result += ",pname:'" + dRow["taobaoname"].ToString() + "'";
                        result += "}";
                    }
                }
                else
                {
                    if (index++ == 0)
                        result = "{[";
                    else
                        result += ",";
                    result += "{";
                    result += "cid:'" + dRow["taobaocid"].ToString() + "'";
                    result += ",name:'" + dRow["taobaoname"].ToString() + "'";
                    result += ",pcid:'0'";
                    result += ",pname:''";
                    result += "}";
                }
            }
            if (index > 0)
                result += "]}";
        }
        return result;
    }

    [AjaxPro.AjaxMethod]
    public bool AddSellerItemCate(string itemRecid, string itemcateId)
    {
        bool result = false;
        taobaouseritems useritems = taobaouseritems.Find("taobaouserid='" + AliApi.appUserId + "' and recid=" + itemRecid);
        if (useritems.Count > 0)
        {
            string oldCatesStr = useritems.taobaoseller_cids.Value;
            oldCatesStr = oldCatesStr.Trim();
            if (oldCatesStr.IndexOf(itemcateId) < 0)
            {
                if (oldCatesStr == string.Empty)
                    oldCatesStr += ",";
                if (oldCatesStr.Substring(oldCatesStr.Length - 1, 1) != ",")
                    oldCatesStr += ",";
                oldCatesStr += itemcateId + ",";
                useritems.taobaoseller_cids.Value = oldCatesStr;
                useritems.Modify();
                result = true;
            }
        }
        return result;
    }


    /// <summary>
    /// 移动 自定义分类的位置
    /// </summary>
    /// <param name="targetCateId">将要移动的分类</param>
    /// <param name="moveAfterCateId">将要移动到其后面的分类，如果为空，则移动到首位</param>
    /// <returns></returns>
    [AjaxPro.AjaxMethod]
    public bool moveCateIdTo(string targetCateId, string moveAfterCateId)
    {
        return taobaoItemCat.moveCateIdTo(targetCateId, moveAfterCateId);
    }

    [AjaxPro.AjaxMethod]
    public bool moveCateId(string targetCateId, bool isMoveDown)
    {
        return taobaoItemCat.moveCateId(targetCateId, isMoveDown);
    }

    [AjaxPro.AjaxMethod]
    public string deleteCateId(string itemcid)
    {
        return taobaoItemCat.deleteCateId(itemcid);
    }

    [AjaxPro.AjaxMethod]
    public string saveNewCateId(string newCateName, string parentCid)
    {
        return taobaoItemCat.saveNewCateId(newCateName ,parentCid );
    }

    /// <summary>
    /// 获取自定义子分类列表 JSON格式
    /// </summary>
    /// <param name="parentCid"></param>
    /// <returns></returns>
    [AjaxPro.AjaxMethod ]
    public string getChildCateList(string parentCid)
    {
        string result = string.Empty;
        if (AliApi.appUserId != string.Empty && parentCid.Trim() != string.Empty)
        {
            taobaoItemCat taobaoitemcate = taobaoItemCat.Find("taobaouserid='"+AliApi.appUserId +"' and taobaoparentcid='"+parentCid +"'");
            if (taobaoitemcate.Count > 0)
            {
                result = "{[";
                for (int i = 0; i < taobaoitemcate.Count; i++)
                {
                    if (i > 0)
                        result += ",";
                    result += "{cid:'"+taobaoitemcate .taobaocid.Value +"',name:'"+taobaoitemcate.taobaoname .Value +"',sort_order:"+taobaoitemcate.taobaosort_order .Value .ToString ()+"}";
                    taobaoitemcate.Next();
                }
                result += "]}";
            }
        }
        return result;
    }

    /// <summary>
    /// 根据自定义分类获取对应分类下面的商品列表 JSON格式
    /// </summary>
    /// <param name="itemcateid"></param>
    /// <returns></returns>
    [AjaxPro.AjaxMethod ]
    public string getItemsFromSellerCateId(string itemcateid)
    {
        string result = string.Empty;
        if (AliApi.appUserId != string.Empty && itemcateid.Trim() != string.Empty)
        {
            taobaouseritems useritems = taobaouseritems.Find("taobaouserid='"+AliApi.appUserId +"' and taobaoseller_cids like '%"+itemcateid +"%'");
            if (useritems.Count > 0)
            {
                result = "{[";
                for (int i = 0; i < useritems.Count; i++)
                {
                    if (i > 0)
                        result += ",";
                    result += "{itemid:'"+useritems.taobaoiid .Value +"',sellercids:'"+useritems.taobaoseller_cids .Value +"',userid:'"+AliApi.appUserId+"'}";
                    useritems.Next();
                }
                result += "]}";
            }
        }
        return result;
    }
    #endregion

    /// <summary>
    /// 获取所有商品分类
    /// </summary>
    /// <returns></returns>
    [AjaxPro .AjaxMethod ]
    public string getAllShopCates()
    {
        string allShopCates = string.Empty;
        taobaoshop_cat shopcates = taobaoshop_cat.Find("1=1");
        if (shopcates.Count > 0)
        {
            int count = 0;
            allShopCates = "{shopcates:[";
            do{
                if (count++ > 0)
                    allShopCates += ",";
                allShopCates += "{id:'"+shopcates.id.Value +"',name:'"+shopcates.taobaoname.Value +"'}";
            }while(shopcates.Next());
            allShopCates += "]}";
        }
        return allShopCates;
    }

    [AjaxPro .AjaxMethod ]
    public string searchs(string searchType,  string keytext, float leftlat, float leftlng, float rightlat, float rightlng,
          string rsms,string qtth,string shwx ,string sdfh,string cateid ,float lowprice,float  highprice)
    {
        string searchResult = string.Empty;
        string sqlText = string.Empty;
        string keytextReplace = map.zfunction.ReplaceKeyWord(keytext);
        if (searchType == "Item")
        {
            sqlText = @"exec [searchitem] "+
                    "@keyword = '" + keytextReplace + "',  " +
                    "@keywordtext = '" + keytext + "'," +
                    "@clat1 = " + leftlat.ToString () + ",        " +
                    "@clong1 = " + leftlng.ToString() + ",        " +
                    "@clat2 = " + rightlat.ToString() + ",         " +
                    "@clong2 = " + rightlng.ToString() + ",        " +
                    "@pricefrom = " + lowprice.ToString() + ",     " +
                    "@priceto = " + highprice.ToString() + ",       " +
                    "@rsms = '" + rsms + "',          " +
                    "@qtth = '" + qtth + "',          " +
                    "@stwx = '" + shwx + "',          " +
                    "@sdfh = '" + sdfh + "',          " +
                    "@cataid = '" + cateid + "'";       
        }
        else
        {
            sqlText = @"exec [searchshop] "+
                    "@keyword = '" + keytextReplace + "'," +
		            "@keywordtext = '"+keytext +"',"+
                    "@clat1 = " + leftlat.ToString() + "," +
                    "@clong1 = " + leftlng.ToString() + "," +
                    "@clat2 = " + rightlat.ToString() + "," +
                    "@clong2 = " + rightlng.ToString() + "," +
                    "@rsms =  '" + rsms  + "'," +
                    "@qtth =  '" + qtth  + "'," +
                    "@stwx =  '" + shwx  + "'," +
		            "@sdfh = '"+sdfh +"',"+
		            "@cataid = '"+cateid +"'";
        }
        DataSet dSet = SqlHelper.Instance.ExecuteQuery(sqlText);
        if (dSet.Tables.Count > 0 && dSet.Tables[0].Rows.Count > 0)
        {
            searchResult = "{[";
            int count = 0;
            foreach (DataRow dRow in dSet.Tables[0].Rows)
            {
                if (count++ > 0)
                    searchResult += ",";
                searchResult += "{id:'"+dRow ["areaRecid"].ToString ()+"',area:'" + dRow["BizAreaName"].ToString() + "',lat:'" + dRow["taobaolat"].ToString() + "',lng:'" + dRow["taobaolong"].ToString() + "',count:" + dRow["cbcount"].ToString() + "}"; 
            }
            searchResult += "]}";
        }
        return searchResult;
    }

    [AjaxPro.AjaxMethod]
    public string searchBBS( string keytext, float leftlat, float leftlng, float rightlat, float rightlng)
    {
        string searchResult = string.Empty;
        string sqlText = string.Empty;
        string keytextReplace = map.zfunction.ReplaceKeyWord(keytext);
        sqlText = @"exec [searchBBS] " +
                "@keyword = '" + keytextReplace + "',  " +
                "@keywordtext = '" + keytext + "'," +
                "@clat1 = " + leftlat.ToString() + ",        " +
                "@clong1 = " + leftlng.ToString() + ",        " +
                "@clat2 = " + rightlat.ToString() + ",         " +
                "@clong2 = " + rightlng.ToString()
                ;
        DataSet dSet = SqlHelper.Instance.ExecuteQuery(sqlText);
        if (dSet.Tables.Count > 0 && dSet.Tables[0].Rows.Count > 0)
        {
            searchResult = "{[";
            int count = 0;
            foreach (DataRow dRow in dSet.Tables[0].Rows)
            {
                if (count++ > 0)
                    searchResult += ",";
                searchResult += "{area:'" + dRow["BizAreaName"].ToString() + "',lat:'" + dRow["taobaolat"].ToString() + "',lng:'" + dRow["taobaolong"].ToString() + "',count:" + dRow["cbcount"].ToString() + "}";
            }
            searchResult += "]}";
        }
        return searchResult;
    }

    [AjaxPro.AjaxMethod]
    public string searchBroker(string keytext, float leftlat, float leftlng, float rightlat, float rightlng)
    {
        string searchResult = string.Empty;
        string sqlText = string.Empty;
        string keytextReplace = map.zfunction.ReplaceKeyWord(keytext);
        sqlText = @"exec [searchbroker] " +
                "@keyword = '" + keytextReplace + "',  " +
                "@keywordtext = '" + keytext + "'," +
                "@clat1 = " + leftlat.ToString() + ",        " +
                "@clong1 = " + leftlng.ToString() + ",        " +
                "@clat2 = " + rightlat.ToString() + ",         " +
                "@clong2 = " + rightlng.ToString()
                ;
        DataSet dSet = SqlHelper.Instance.ExecuteQuery(sqlText);
        if (dSet.Tables.Count > 0 && dSet.Tables[0].Rows.Count > 0)
        {
            searchResult = "{[";
            int count = 0;
            foreach (DataRow dRow in dSet.Tables[0].Rows)
            {
                if (count++ > 0)
                    searchResult += ",";
                searchResult += "{area:'" + dRow["BizAreaName"].ToString() + "',lat:'" + dRow["taobaolat"].ToString() + "',lng:'" + dRow["taobaolong"].ToString() + "',count:" + dRow["cbcount"].ToString() + "}";
            }
            searchResult += "]}";
        }
        return searchResult;
    }
    [AjaxPro.AjaxMethod ]
    public string ChangeCurrentProvince(string newProvince)
    {
        string latLngJson = string.Empty;
        map.zfunction.Province = newProvince;
        return latLngJson;
    }

    /// <summary>
    /// 当前省份的优先顺序：用户所在地 cookie ip地址所在地
    /// </summary>
    /// <returns></returns>
    [AjaxPro.AjaxMethod ]
    public string getUserLocation(string userRecid)
    {
        string result = string.Empty;
        if (userRecid.Trim() != string.Empty)
        {
            cbuser user = cbuser.Find("RECID=" + userRecid );
            if (user.Count > 0)
            {
                result = "{";
                result += "state:'"+user.省编码.Value +"',city:'"+user.县编码 .Value +"',district:'"+user.区编码 .Value
                         + "',area:'" + user.区域编码.Value + "',bizarea:'" + user.cbUserBizArea.Value + "',lat:" + user.taobaolat.Value.ToString() + ",lng:" + user.taobaolong.Value.ToString()
                         +",userid:'"+user.cbuserid.Value +"',nick:'"+user.cbusernickname .Value +"',name:'"+user.cbname.Value +"',imgPath:'"+user.cbimgpath.Value +"'";
                result += "}";
            }
        }
        return result;
    }
    [AjaxPro.AjaxMethod ]
    public void setCurrentState(string state)
    {
        map.zfunction.Province = state;
    }

    [AjaxPro.AjaxMethod ]
    public string getCurrentState()
    {
        return map.zfunction.Province;
    }


    [AjaxPro.AjaxMethod ]
    public string GetCurrentUserId()
    {
        return AliApi.appUserId;
    }
    [AjaxPro.AjaxMethod ]
    public string GetCurrentUserRECId()
    {
        return AliApi.appDomainID;
    }

    /// <summary>
    /// 获取当前用户信息
    /// </summary>
    /// <returns></returns>
    [AjaxPro.AjaxMethod ]
    public string GetCurrentUserInfo()
    {
        string result = string.Empty;
        cbuser user = cbuser.Find("cbuserid='"+AliApi.appUserId +"'");
        if (user.Count > 0)
        {
            result = "{id:'"+user.cbuserid.Value +"',name:'"+user.cbname .Value 
                +"',nick:'"+user.cbusernickname .Value +"',recid:'"+user.RECID.ToString ()+"'}";
        }
        return result;
    }

    /// <summary>
    /// 获取用户的 店铺中的自定义类目列表
    /// </summary>
    /// <param name="userid">如果为空，则返回当前用户的类目列表</param>
    /// <returns></returns>
    [AjaxPro.AjaxMethod ]
    public string GetUserSellerCateList(string userid)
    {
        string result = string.Empty;
        if (userid == string.Empty)
            userid = AliApi.appUserId;
        if (userid != string.Empty)
        {
            taobaoItemCat taobaoitemcate = taobaoItemCat.Find("taobaouserid='"+userid +"'","taobaosort_order asc");
            if (taobaoitemcate.Count > 0)
            {
                DataRow[] firstLevelRows = taobaoitemcate.Select("taobaoparentcid='0'", "taobaosort_order asc");
                if (firstLevelRows.Length > 0)
                {
                    result = "{[";
                    for (int i = 0; i < firstLevelRows.Length; i++)
                    {
                        if (i > 0)
                            result += ",";
                        result += "{";
                        result += "cid:'" + firstLevelRows[i]["taobaocid"].ToString() + "',name:'" + firstLevelRows[i]["taobaoname"].ToString() + "',order:"
                                 + firstLevelRows[i]["taobaosort_order"].ToString() + ",pcid:'" + firstLevelRows[i]["taobaoparentcid"].ToString();
                        string childResult = string.Empty;
                        DataRow[] secondLevelRows = taobaoitemcate.Select("taobaoparentcid='" + firstLevelRows[i]["taobaocid"].ToString() + "'", "taobaosort_order asc");
                        if (secondLevelRows.Length > 0)
                        {
                            childResult = "[";
                            for (int j = 0; j < secondLevelRows.Length; j++)
                            {
                                if (j > 0)
                                    childResult += ",";
                                childResult += "{";
                                childResult += "cid:'" + secondLevelRows[j]["taobaocid"].ToString() + "',name:'" + secondLevelRows[j]["taobaoname"].ToString() + "',order:"
                                 + secondLevelRows[j]["taobaosort_order"].ToString() + ",pcid:'" + secondLevelRows[j]["taobaoparentcid"].ToString()+"'";
                                childResult += "}";
                            }
                            childResult += "]";
                        }
                        //childResult = "[{cid:1,b:2,c:3},{cid:1,b:2,c:4}]";
                        if (childResult == string.Empty)
                            childResult = "[]";
                        result += "',childCids:"+childResult +"";
                        result += "}";
                    }
                    result += "]}";
                }
            }
        }
        return result;
    }

    [AjaxPro.AjaxMethod ]
    public string GetSessionValue(string key)
    {
        string sessionValue = string.Empty;
        if (HttpContext.Current.Session[key] != null)
        {
            sessionValue = HttpContext.Current.Session[key].ToString();
        }
        return sessionValue;
    }


    /// <summary>
    /// 验证密码
    /// </summary>
    /// <param name="userid"></param>
    /// <param name="password"></param>
    /// <returns></returns>
    [AjaxPro.AjaxMethod ]
    public bool ValidatePassword(string userid, string password)
    {
        return cbuser.ValidatePassword(userid, password);
    }



    #region 支付平台相关
    /// <summary>
    /// 首信易支付
    /// </summary>
    /// <returns></returns>
    [AjaxPro.AjaxMethod ]
    public string GetDefaultReceiverInfo()
    {
        string result = string.Empty;
        result += "{";
        result += "v_mid:'"+PayEaseUtil .v_mid +"'";
        result += ",v_rcvname:'"+PayEaseUtil.s_v_rcvname +"'";
        result += ",v_rcvaddr:'" + PayEaseUtil.s_v_rcvaddr + "'";
        result += ",v_rcvtel:'" + PayEaseUtil.s_v_rcvtel + "'";
        result += ",v_rcvpost:'"+PayEaseUtil.s_v_rcvpost +"'";
        result += ",v_url:'"+PayEaseUtil.im_v_url +"'";
        result += "}";
        return result;
    }

    /// <summary>
    /// 动态生成订单ID
    /// </summary>
    /// <returns></returns>
    [AjaxPro .AjaxMethod ]
    public string GeneratorOrderId()
    {
        return GetGuidId();
    }

    /// <summary>
    /// 提交订单生成数字指纹，供v_md5info使用
    /// </summary>
    /// <param name="v_moneytype"></param>
    /// <param name="v_ymd"></param>
    /// <param name="v_amount"></param>
    /// <param name="v_rcvname"></param>
    /// <param name="v_oid"></param>
    /// <param name="v_mid"></param>
    /// <param name="v_url"></param>
    /// <returns></returns>
    [AjaxPro.AjaxMethod ]
    public string GetHex_MD5Info(string v_moneytype, string v_ymd, string v_amount, string v_rcvname, string v_oid, string v_mid, string v_url)
    {
        return PayEaseUtil.Hex_MD5Info(v_moneytype, v_ymd, v_amount, v_rcvname, v_oid, v_mid, v_url);
    }

    /// <summary>
    /// 生成首信易支付平台订单提交日志
    /// </summary>
    /// <param name="parmStr">订单提交参数列表</param>
    /// <returns>生成日志正确，返回空；否则返回错误信息</returns>
    [AjaxPro .AjaxMethod ]
    public string MakeOrderTrans(string queryStr)
    {
        string result = string.Empty;
        string v_mid = getQueryString("v_mid", queryStr);
        string v_oid = getQueryString("v_oid", queryStr);
        string v_rcvname = getQueryString("v_rcvname", queryStr);
        string v_rcvaddr = getQueryString("v_rcvaddr", queryStr);
        string v_rcvtel = getQueryString("v_rcvtel", queryStr);
        string v_rcvpost = getQueryString("v_rcvpost", queryStr);
        string v_amount = getQueryString("v_amount", queryStr);
        string v_ymd = getQueryString("v_ymd", queryStr);
        string v_orderstatus = getQueryString("v_orderstatus", queryStr);
        string v_ordername = getQueryString("v_ordername", queryStr);
        string v_moneytype = getQueryString("v_moneytype", queryStr);
        string v_md5info = getQueryString("v_md5info", queryStr);
        string v_url = getQueryString("v_url", queryStr);
        string v_pmode = getQueryString("v_pmode", queryStr);
        try
        {
            cbPayEaseOrderTrans orderTrans = cbPayEaseOrderTrans.Find("v_oid='" + v_oid + "'");
            if (orderTrans.Count > 0)
            {
                result = "已经存在该订单！";
            }
            else
            {
                orderTrans.New();
                orderTrans.v_amount.Value = v_amount;
                orderTrans.v_md5info.Value = v_md5info;
                orderTrans.v_mid.Value = v_mid;
                orderTrans.v_moneytype.Value = v_moneytype;
                orderTrans.v_oid.Value = v_oid;
                orderTrans.v_ordername.Value = v_ordername;
                orderTrans.v_orderstatus.Value = v_orderstatus;
                orderTrans.v_pmode.Value = v_pmode;
                orderTrans.v_rcvaddr.Value = v_rcvaddr;
                orderTrans.v_rcvname.Value = v_rcvname;
                orderTrans.v_rcvpost.Value = v_rcvpost;
                orderTrans.v_rcvtel.Value = v_rcvtel;
                orderTrans.v_url.Value = v_url;
                orderTrans.v_ymd.Value = v_ymd;
                orderTrans.Insert();
            }
        }
        catch (Exception e)
        {
            result = e.Message;
        }
        return result;
    }
    
    #endregion
    #endregion

    #region cookie相关
    [AjaxPro.AjaxMethod ]
    public string GetCookie(string name,string key)
    {
        if (HttpContext.Current.Request.Cookies[name] != null && HttpContext.Current.Request.Cookies[name][key] != null)
            return HttpContext.Current.Server .UrlDecode  (HttpContext.Current.Request.Cookies[name][key]);
        return "";
    }

    [AjaxPro .AjaxMethod ]
    public void SetCookie(string name, string key, string value)
    {
        if (HttpContext.Current.Request.Cookies[name] == null)
        {
            HttpCookie cookie = new HttpCookie(name);
            cookie.Values.Add(key, HttpContext.Current.Server .UrlEncode ( value));
            cookie.Expires = DateTime.Now.AddDays(2);
            HttpContext.Current.Response .Cookies.Add(cookie);
        }
        else
        {
            HttpCookie cookie = HttpContext.Current.Request.Cookies[name];
            cookie[key]= HttpContext.Current.Server.UrlEncode(value);
            cookie.Expires = DateTime.Now.AddDays(2);
            HttpContext.Current.Response.Cookies.Add(cookie);

            //HttpContext.Current.Response.Cookies[name][key] =HttpContext.Current.Server .UrlEncode ( value);
            //HttpContext.Current.Response.Cookies[name].Expires = DateTime.Now.AddDays(2);
        }
    }
    #endregion

    #region 辅助方法
    /// <summary>
    /// 获取变量值
    /// </summary>
    /// <param name="key"></param>
    /// <param name="allQueryText"></param>
    /// <returns></returns>
    private string getQueryString(string key, string allQueryText)
    {
        string result = string.Empty;
        int start = allQueryText.IndexOf(key + "=");
        if (start >= 0)
        {
            int end = allQueryText.IndexOf("&", start);
            if (end > (start + key.Length + 1))
            {
                result = allQueryText.Substring(start + key.Length + 1, end - start - key.Length - 1);
            }
            else
            {
                if (end == -1)
                {
                    result = allQueryText.Substring(start + key.Length + 1, allQueryText.Length - start - key.Length - 1);
                }
            }
        }
        return result;
    }
    #endregion

    #region 设计页面样式相关
    /// <summary>
    /// 修改店铺css样式文件
    /// </summary>
    /// <param name="cssName">样式文件名，不包括后缀和路径</param>
    /// <returns></returns>
    [AjaxPro.AjaxMethod ]
    public string changeShopStyle(string cssName)
    {
        string errorMsg = string.Empty;
        if (AliApi.appUserId != string.Empty)
        {
            cbshop shop = cbshop.Find("cbuserid='" + AliApi.appUserId + "'");
            if (shop.Count > 0)
            {
                shop.cbshopcssfilename.Value = cssName;
                shop.cbshopbannerpic.Value = string.Empty;
                shop.cbitembannerpic.Value = string.Empty;
                shop.Modify();
            }
            else
            {
                errorMsg = "当前店铺不存在！";
            }
        }
        else
        {
            errorMsg = "您还未登录，请先登录！";
        }
        return errorMsg;
    }

    /// <summary>
    /// 清空店铺页面的标题栏图片
    /// </summary>
    /// <returns></returns>
    [AjaxPro .AjaxMethod ]
    public string clearBanner()
    {
        string result = string.Empty ;
        if (AliApi.appUserId != null)
        {
            cbshop shop = cbshop.Find("cbuserid='" + AliApi.appUserId + "'");
            if (shop.Count > 0)
            {
                shop.cbshopbannerpic.Value = string.Empty;
                shop.cbitembannerpic.Value = string.Empty;
                shop.Modify();
                return string.Empty;
            }
            result = "当前用户:" + AliApi.appUserId + " 没有开通店铺！";
        }
        else {
            result = "您还未登录！";
        }

        return result;
    }
    #endregion

}

